package com.example.springLearning.part5.controller;

import com.example.springLearning.part5.entity.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/spring/part5")
@Slf4j
public class part5Controller2 {

    @Value("${spring.part5.user.username}")
    private String username;

    @Value("${spring.part5.user.password}")
    private String password;

//    public part5Controller2(Student student) {
//        this.student = student;
//    }

    @Autowired
    private ApplicationContext context;

    private List<Student> students;

    public part5Controller2(List<Student> students) {
        this.students = students;
    }

    @RequestMapping(path = "user", method = RequestMethod.GET)
    public String hi() {
        return username + password;
    }

//    @Resource
    private Student student;

    @RequestMapping(path = "bean", method = RequestMethod.GET)
    public String hi2() {
        System.out.println(context.getBean("studentabc"));
        System.out.println(context.getBean("student1"));
       // System.out.println(student);
        return username + password;
    }

    @RequestMapping(path = "students", method = RequestMethod.GET)
    public String students() {

        for (Student student: students) {
            System.out.println(student.toString());
        }
        return "";
    }
}
